﻿package core.image.encoder
{
    import __AS3__.vec.*;
    import core.image.*;
    import flash.utils.*;

    public class PBREncoder extends Object
    {
        public const version:int = 1;

        public function PBREncoder()
        {
            return;
        }// end function

        public function encode(core.image.encoder:PBREncoder:Vector.<Brush>) : ByteArray
        {
            var _loc_2:int = 0;
            var _loc_3:ByteArray = null;
            var _loc_4:* = new ByteArray();
            _loc_4.writeShort(this.version);
            _loc_4.writeShort(core.image.encoder:PBREncoder.length);
            while (_loc_2 < core.image.encoder:PBREncoder.length)
            {
                
                _loc_3 = this.WriteBrush(core.image.encoder:PBREncoder[_loc_2]);
                _loc_4.writeUnsignedInt(_loc_3.length);
                _loc_4.writeBytes(_loc_3);
                _loc_2++;
            }
            _loc_4.compress();
            return _loc_4;
        }// end function

        private function WriteBrush(core.image.encoder:PBREncoder:Brush) : ByteArray
        {
            var _loc_3:int = 0;
            var _loc_2:* = new ByteArray();
            _loc_2.writeInt(core.image.encoder:PBREncoder.width);
            _loc_2.writeInt(core.image.encoder:PBREncoder.height);
            _loc_2.writeInt(core.image.encoder:PBREncoder.step);
            _loc_2.writeUnsignedInt(core.image.encoder:PBREncoder.data.length);
            while (_loc_3 < core.image.encoder:PBREncoder.data.length)
            {
                
                _loc_2.writeByte(core.image.encoder:PBREncoder.data[_loc_3]);
                _loc_3++;
            }
            return _loc_2;
        }// end function

    }
}
